package cn.always.xiajia.framework.mybatis.config;

import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;

import cn.always.xiajia.framework.mybatis.core.handler.DefaultDBFieldHandler;

@AutoConfiguration
@MapperScan(value = "${xj.info.base-package}", annotationClass = Mapper.class)
public class XiaJiaMybatisAutoConfiguration {

	/**
	 * 分页插件
	 * 
	 * @return
	 */
	@Bean
	MybatisPlusInterceptor mybatisPlusInterceptor() {
		MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
		mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
		return mybatisPlusInterceptor;
	}

	/**
	 * 自动填充参数类
	 * 
	 * @return
	 */
	@Bean
	public MetaObjectHandler defaultMetaObjectHandler() {
		return new DefaultDBFieldHandler();
	}

}
